<%@ page import="java.util.List" %>
<%@ page import="com.mystore.vo.GoodVO" %>
<%@ page import="com.mystore.util.PageUtil" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="utf-8"/>
    <title>分类显示</title>
    <link href="../../css/main.css" rel="stylesheet">
    <style>
        table thead tr th{
            text-align: center;
        }
    </style>


</head>
<body>

<div class="container text-center">
    <div class="row">
        <jsp:include page="head.jsp"/>
        <div class=" table-responsive">
            <caption><h2>商品分类显示信息</h2></caption>
            <table class="table table-bordered table-hover  text-center" >
                <thead>
                <tr >
                    <th>编号</th>
                    <th>名称</th>
                    <th>详细信息</th>
                    <th>价格(元)</th>
                    <th>数量(个)</th>
                    <th>类型</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody

                <%
                    PageUtil<GoodVO> pageUtil = (PageUtil<GoodVO>) request.getAttribute("goods");
                    int gid = (int) request.getAttribute("gid");
                    int pageSize = pageUtil.getPageSize();
                    String baseUrl = request.getContextPath() + "/check/good/getGoods";
                    String url = baseUrl + "?gid=" + gid + "&pageSize=" + pageSize + "";
                    List<GoodVO> list = pageUtil.getList();

                    for (GoodVO goodVO : list) {
                %>
                <tr>
                    <td><%=goodVO.getId()%>
                    </td>
                    <td><%=goodVO.getName()%>
                    </td>
                    <td><%=goodVO.getMsg()%>
                    </td>
                    <td><%=goodVO.getPrice()%>
                    </td>
                    <td><%=goodVO.getNum()%>
                    </td>

                    <td><%=goodVO.getKind()%>
                    </td>
                    <td>
                        <a href="<%=request.getContextPath()%>/check/cart/addCart?gid=<%=goodVO.getId()%>">添加到购物车</a></td>
                </tr>

                <%


                    }
                %>
                </tbody>


            </table>
        </div>

    </div>

    <div class="row">
        <div class="pager">
            总共:<%=pageUtil.getPageNumber()%>/<%=pageUtil.totalPage()%>页

            <%--设置显示条数--%>
            每页显示:<select class="dropdown" name="pageSize" id="pageSize">
            <option value="3">3</option>
            <option value="4">4</option>
            <option value="5">5</option>
            <option value="10">10</option>
            <option value="50">50</option>
            <option value="100">100</option>
        </select>
            <a id="sele" href="">设置每页显示记录数</a>
        </div>


        <ul class=" pagination pagination-lg">

            <li><a href="<%=url%>&pageNumber=<%=pageUtil.headPage()%>">首页</a></li>
            <li><a href="<%=url%>&pageNumber=<%=pageUtil.prePage()%>">上一页</a></li>
            <%
                int pageNumber = pageUtil.totalPage();
                for (int i = 1; i <= pageNumber; i++) {
            %>
            <li><a href="<%=baseUrl%>?gid=<%=gid%>&pageNumber=<%=i%>&pageSize=<%=pageSize%>"><%=i%>
            </a></li>
            <%
                }
            %>
            <li><a href="<%=url%>&pageNumber=<%=pageUtil.nextPage()%>">下一页</a></li>
            <li><a href="<%=url%>&pageNumber=<%=pageUtil.lastPage()%>">尾页</a></li>

        </ul>
    </div>
</div>
</body>
</html>
<script src="../../js/jquery-1.8.3.min.js"></script>

<script>
    var pageNumber = "<%=pageUtil.getPageNumber()%>";
    var pageSize = "<%=pageSize%>";
    console.log("pageSize=" + pageSize)
    $("#pageSize").val(pageSize);
    $("#sele").on("click", function () {
        var pageSize = $("#pageSize").val();
        console.log("pageSize=" + pageSize);
        $(this).attr("href", "<%=baseUrl%>?gid=<%=gid%>&pageNumber=" + pageNumber + "&pageSize=" + pageSize);
//        window.location.href=;
    })
</script>